package com.evan.review.ipc;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 可序列化的消息对象
 * 用于在进程间传递数据
 */
public class MessageParcel implements Parcelable {
    private int id;
    private String content;
    private long timestamp;
    private int fromPid;

    public MessageParcel() {
        this.timestamp = System.currentTimeMillis();
    }

    public MessageParcel(int id, String content, int fromPid) {
        this.id = id;
        this.content = content;
        this.timestamp = System.currentTimeMillis();
        this.fromPid = fromPid;
    }

    // Parcelable实现
    protected MessageParcel(Parcel in) {
        id = in.readInt();
        content = in.readString();
        timestamp = in.readLong();
        fromPid = in.readInt();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(content);
        dest.writeLong(timestamp);
        dest.writeInt(fromPid);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<MessageParcel> CREATOR = new Creator<MessageParcel>() {
        @Override
        public MessageParcel createFromParcel(Parcel in) {
            return new MessageParcel(in);
        }

        @Override
        public MessageParcel[] newArray(int size) {
            return new MessageParcel[size];
        }
    };

    // Getters and Setters
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public int getFromPid() {
        return fromPid;
    }

    public void setFromPid(int fromPid) {
        this.fromPid = fromPid;
    }

    @Override
    public String toString() {
        return "MessageParcel{" +
                "id=" + id +
                ", content='" + content + '\'' +
                ", timestamp=" + timestamp +
                ", fromPid=" + fromPid +
                '}';
    }
} 